//
//  TbInfoNewView.swift
//  SlaughterClient
//
//  Created by 邱仙凯 on 2024/8/5.
//  Copyright © 2024 zwb. All rights reserved.
//

import UIKit
class TbInfoNewView: UIView {
   private var topLine:UIView = {
        var v = UIView()
        v.backgroundColor = UIColor(kshex: "f6f6f6")
        return v
    }()
    private var bottomLine:UIView = {
        var v = UIView()
        v.backgroundColor = UIColor(kshex: "f6f6f6")
        return v
    }()
    var fontx:CGFloat = 16
    var content1 = CJLabel(frame: CGRect.zero)
    var contLinkLabel = CJLabel(frame: CGRect.zero)
    var contContentLabel = CJLabel(frame: CGRect.zero)

 
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = .white
        self.addSubview(topLine)
        self.addSubview(bottomLine)
        self.addSubview(content1)
        self.addSubview(contLinkLabel)
        contLinkLabel.font = UIFont.systemFont(ofSize: fontx)
        self.addSubview(contContentLabel)
        contContentLabel.textColor = UIColor(kshex: tenderBlue)
         
        content1.snp.makeConstraints { make in
            make.edges.equalTo(UIEdgeInsets(top: 20, left: 10, bottom: 20, right: 10))
        }
        topLine.snp.makeConstraints { make in
            make.top.left.right.equalToSuperview()
            make.height.equalTo(10)
        }
        bottomLine.snp.makeConstraints { make in
            make.bottom.left.right.equalToSuperview()
            make.height.equalTo(10)
        }
        content1.enableCopy = true
        content1.font = UIFont.systemFont(ofSize: fontx)
        content1.numberOfLines = 0
        content1.textAlignment = .left
        content1.preferredMaxLayoutWidth = KSGlobal.screenW - 32
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
  
 
    // 后面复制，与上面同左宽
    var contentLinkStr:String = "" {
        didSet {
            let keyOri = contentLinkStr.preChar(char: ":").unwrap
            let valueOri = contentLinkStr.replacingOccurrences(of: "\(keyOri):", with: "")
            
            contLinkLabel.text = keyOri
           
            
            
            let attributedString = NSMutableAttributedString(string: valueOri)
            attributedString.addAttribute(.underlineStyle, value: NSUnderlineStyle.single.rawValue, range: NSRange(location: 0, length: attributedString.length))
            attributedString.addAttribute(NSAttributedString.Key.font, value: UIFont.systemFont(ofSize: 16), range: NSRange(location: 0, length: attributedString.length))
            attributedString.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor(kshex: tenderBlue), range: NSRange(location: 0, length: attributedString.length))

            
            contContentLabel.attributedText = attributedString
    
            contLinkLabel.snp.remakeConstraints { make in
                make.left.equalTo(content1)
                make.top.equalToSuperview().offset(20)
                
            }
            contContentLabel.snp.remakeConstraints { make in
                make.left.equalToSuperview().offset(content1.maxKeyLength + 9)
                make.top.equalToSuperview().offset(20)
            }
            
            content1.snp.remakeConstraints { make in
//                make.edges.equalTo(UIEdgeInsets(top: 20, left: 10, bottom: 5, right: 10))
                make.top.equalTo(contLinkLabel.snp.bottom).offset(6)
                make.left.equalToSuperview().offset(10)
                make.right.equalToSuperview().offset(-10)
                make.bottom.equalToSuperview().offset(-20)
            }
        }
    }
 
  
    
}
 
 
